|
Pointer syntax can be
confusing, because pointers can both give the memory location and give the
actual value stored in that same location. When a pointer is declared, the
syntax is this: variable_type *name; Notice the *. This is the key to
declaring a pointer, if you use it before the variable name, it will declare
the variable to be a pointer.
There are two ways to use the pointer to access information about the memory
address it points to. It is possible to have it give the actual address to
another variable, or to pass it into a function. To do so, simply use the
name of the pointer without the *. However, to access the actual memory
location, use the *. The technical name for this doing this is dereferencing.
In order to have a pointer actually point to another variable
it is necessary to have the memory address of that variable also. To get the
memory address of the variable, put the & sign in front of the variable
name. This makes it give its address. This is called the reference operator,
because it returns the memory address.
|